/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */



/*
function createIntput(Value, Class, style) {


    var td = document.createElement('td');
    td.style.fontSize = '10pt';

    var myinput = document.createElement('input');
    myinput.setAttribute('class', Class);


    if (Value != null && Value != undefined && Value != "undefined") {
        myinput.setAttribute('value', Value);


    }


    myinput.setAttribute('style', style);

    td.appendChild(myinput);
    return td

}
*/
function createLabel(Value) {

    var td = document.createElement('td');
    td.style.fontSize = '10pt';
    mxUtils.write(td, Value);
    return td;

}


function getDataValue(Class, num) {

    var returnData = ""
    var mydata = $("." + Class).val();
    if (mydata != null) {


        mydata = unescape(mydata);
        var Classv = mydata.split(";");
        var Classv2 = Classv[1].split("__");

        returnData = Classv2[num];
    }
    return returnData;
}



function gatDataValuec(mydata, num) {


    var returnData = ""


    if (mydata != null) {
        mydata = unescape(mydata);
        var Classv = mydata.split(";");
        var Classv2 = Classv[1].split("__");

        returnData = Classv2[num];
    }
    return returnData;



}


function addDatasetParameters() {


    var num = 0;
    $(".serEventdata.modelDatal").each(function() {
        num++;
        var id = "serEventdata";
        $("#" + id).parent().parent("tr").after('<tr class="' + id + ' addprow morerow" style="display: table-row;"><td style="font-size: 10pt;">Value:</td><td style="font-size: 10pt;"><input class="' + id + '_event" style="width:100px;" value="' + gatDataValuec($(this).val(), 0) + '"></td><td style="font-size: 10pt;">Display Name:</td><td style="font-size: 10pt;"><input class="' + id + '_DisplayName" style="width:100px;" value="' + gatDataValuec($(this).val(), 1) + '" ></td></tr>');

    })

    if (num > 0)
    {

        $(".chadd_ser").attr("checked", "checked");
        $(".serTable .addprow").show();
    }

    num = 0;
    $(".merEventdata.modelDatal").each(function() {
        num++;

        var id = "merEventdata";
        $("#" + id).parent().parent("tr").after('<tr class="' + id + ' addprow morerow" style="display: table-row;"><td style="font-size: 10pt;">Value:</td><td style="font-size: 10pt;"><input class="' + id + '_event" style="width:100px;" value="' + gatDataValuec($(this).val(), 0) + '"></td><td style="font-size: 10pt;">Display Name:</td><td style="font-size: 10pt;"><input class="' + id + '_DisplayName" style="width:100px;" value="' + gatDataValuec($(this).val(), 1) + '" ></td></tr>');


    })

    if (num > 0)
    {

        $(".chadd_mer").attr("checked", "checked");

        $(".merTable .addprow").show();

    }

}

function addmore(id) {

    $("#" + id).parent().parent("tr").after('<tr class="' + id + ' addprow morerow" style="display: table-row;"><td style="font-size: 10pt;">Value:</td><td style="font-size: 10pt;"><input class="' + id + '_event" style="width:100px;"></td><td style="font-size: 10pt;">Display Name:</td><td style="font-size: 10pt;"><input class="' + id + '_DisplayName" style="width:100px;"></td></tr>');


}


function doOnLoad() {

    $(".addprow").hide();

    addDatasetParameters();



    $(".chadd").change(function() {

        var tbClass = $(this).parent("td").parent("tr").parent().parent("table").attr("class");

        if ($(this).is(':checked')) {



            $("." + tbClass + " .addprow").show()
        } else {

            $("." + tbClass + " .addprow").hide()

        }



    })

}
function modUpdateItemDialog(editorUi, mxUtils)
{

    var div = document.createElement('div');
    var divd1 = document.createElement('div');

    div.appendChild(createItem("State Model Initial Properties", "", "thtitle"));

    var table = document.createElement('table');
    table.style.width = '100%';
    table.style.height = '100%';
    var tbody = document.createElement('tbody');


    row = document.createElement('tr');

    row.appendChild(createLabel('State Model Name:'));
   
    row.appendChild(createIntput(Chtml($(".modleName").val()), "modleNamev", 'width:100px;'));
    tbody.appendChild(row);


    table.appendChild(tbody);
    divd1.appendChild(table);

    div.appendChild(divd1);

    $(".tabs").click(function() {



    })






    var mi = mxUtils.button("Migrate", function()
    {

        $(".tabs").removeClass("selected");
        $(".mi").addClass("selected");

        $(".divt3").hide("slow");
        $(".divt2").hide("slow");
        $(".divt1").show("slow");


    });

    mi.setAttribute('class', 'tabs mi selected');


    var me = mxUtils.button("Migrate-Error-Resolve", function()
    {

        $(".tabs").removeClass("selected");
        $(".me").addClass("selected");
        $(".divt3").hide("slow");
        $(".divt2").show("slow");
        $(".divt1").hide("slow");


    })
    me.setAttribute('class', 'tabs me');

    var se = mxUtils.button("Synchronise-Error-Resolve", function()
    {
        $(".tabs").removeClass("selected");
        $(".se").addClass("selected");



        $(".divt2").hide("slow");
        $(".divt1").hide("slow");

        $(".divt3").show("slow");
    })

    se.setAttribute('class', 'tabs se');

    div.appendChild(createItem("Dataset Properties", "", "subtitle"));

    div.appendChild(mi);

    div.appendChild(me);

    div.appendChild(se);



    var myinput = 0;










    divd1 = document.createElement('div');

    divd1.setAttribute('class', 'divt1');


    var script = document.createElement("script");
    script.type = "text/javascript";
    script.src = "file.js";
    script.onload = function() {
        doOnLoad();
    };
    divd1.appendChild(script);



    table = document.createElement('table');
    table.style.width = '100%';
    table.style.height = '100%';
    tbody = document.createElement('tbody');




    row = document.createElement('tr');


    row.appendChild(createLabel('Event:'));

    row.appendChild(createIntput(getDataValue("migrateEvent", 0), "migrate_event", 'width:100px;'));



    td = document.createElement('td');

    row.appendChild(createLabel('Display Name:'));


    row.appendChild(createIntput(getDataValue("migrateEvent", 1), "migrate_DisplayName", 'width:100px;'));




    tbody.appendChild(row);
    table.appendChild(tbody);
    divd1.appendChild(table);

    div.appendChild(divd1);






    var divd2 = document.createElement('div');

    divd2.setAttribute('class', 'divt2');

    divd2.setAttribute('style', 'display:none;');

    var table = document.createElement('table');


    table.setAttribute('class', 'merTable');

    table.style.width = '100%';
    table.style.height = '100%';
    var tbody = document.createElement('tbody');




    row = document.createElement('tr');
    row.appendChild(createLabel('Event:'));




    row.appendChild(createIntput(getDataValue("mer.modelDatal", 0), "mer_event", 'width:100px;'));

    row.appendChild(createLabel('Display Name:'));


    row.appendChild(createIntput(getDataValue("mer.modelDatal", 1), "mer_DisplayName", 'width:100px;'));

    tbody.appendChild(row);



    row = document.createElement('tr');

    td = document.createElement('td');
    td.style.fontSize = '10pt';

    myinput = document.createElement('input');

    myinput.setAttribute("type", "checkbox");



    myinput.setAttribute('class', 'chadd chadd_mer');

    td.appendChild(myinput);
    row.appendChild(td);
    td = document.createElement('td');
    td.style.fontSize = '10pt';
    td.setAttribute('colspan', '3');
    mxUtils.write(td, 'Add Parameters');
    row.appendChild(td);
    tbody.appendChild(row);





    row = document.createElement('tr');
    row.setAttribute('class', 'addprow');
    td = document.createElement('td');
    td.style.fontSize = '10pt';
    td.setAttribute('colspan', '3');
    td.setAttribute('class', 'subtitle');
    mxUtils.write(td, 'EventData');
    row.appendChild(td);
    tbody.appendChild(row);


    row = document.createElement('tr');
    row.setAttribute('class', 'addprow');
    td = document.createElement('td');
    td.style.fontSize = '10pt';
    myinput = document.createElement('input');
    myinput.setAttribute('class', 'addmore');
    myinput.setAttribute('id', 'merEventdata');
    myinput.setAttribute('value', '+');
    myinput.setAttribute('type', 'button');
    myinput.onclick = function() {
        addmore("merEventdata");
    }
    td.appendChild(myinput);

    row.appendChild(td);
    tbody.appendChild(row);



    row = document.createElement('tr');
    row.setAttribute('class', 'addprow');
    td = document.createElement('td');
    td.style.fontSize = '10pt';


    td.setAttribute('colspan', '3');

    td.setAttribute('class', 'subtitle ');

    mxUtils.write(td, 'Event - Data pattern');



    row.appendChild(td);
    tbody.appendChild(row);



    row = document.createElement('tr');

    row.setAttribute('class', 'addprow');

    row.appendChild(createLabel('Event:'));




    row.appendChild(createIntput(getDataValue("mer_pattern.modelDatal", 0), "mer_pattern_value", 'width:100px;'));





    row.appendChild(createLabel('Display Name:'));



    row.appendChild(createIntput(getDataValue("mer_pattern.modelDatal", 1), "mer_pattern_DisplayName", 'width:100px;'));



    tbody.appendChild(row);


    table.appendChild(tbody);
    divd2.appendChild(table);





    div.appendChild(divd2);

    var divd2 = document.createElement('div');

    divd2.setAttribute('class', 'divt3');

    divd2.setAttribute('style', 'display:none;');

    var table = document.createElement('table');


    table.setAttribute('class', 'serTable');

    table.style.width = '100%';
    table.style.height = '100%';
    var tbody = document.createElement('tbody');


    row = document.createElement('tr');
    row.appendChild(createLabel('Event:'));



    row.appendChild(createIntput(getDataValue("ser.modelDatal", 0), "ser_event", 'width:100px;'));



    row.appendChild(createLabel('Display Name:'));



    row.appendChild(createIntput(getDataValue("ser.modelDatal", 1), "ser_DisplayName", 'width:100px;'));


    tbody.appendChild(row);


    row = document.createElement('tr');

    td = document.createElement('td');
    td.style.fontSize = '10pt';

    myinput = document.createElement('input');

    myinput.setAttribute("type", "checkbox");



    myinput.setAttribute('class', 'chadd chadd_ser');

    td.appendChild(myinput);
    row.appendChild(td);
    td = document.createElement('td');
    td.style.fontSize = '10pt';
    td.setAttribute('colspan', '3');
    mxUtils.write(td, 'Add Parameters');
    row.appendChild(td);
    tbody.appendChild(row);





    row = document.createElement('tr');
    row.setAttribute('class', 'addprow');
    td = document.createElement('td');
    td.style.fontSize = '10pt';
    td.setAttribute('colspan', '3');
    td.setAttribute('class', 'subtitle ');
    mxUtils.write(td, 'EventData');
    row.appendChild(td);
    tbody.appendChild(row);


    row = document.createElement('tr');
    row.setAttribute('class', 'addprow');
    td = document.createElement('td');
    td.style.fontSize = '10pt';
    myinput = document.createElement('input');
    myinput.setAttribute('class', 'addmore');

    myinput.setAttribute('id', 'serEventdata');
    myinput.setAttribute('value', '+');
    myinput.setAttribute('type', 'button');


    myinput.onclick = function() {
        addmore("serEventdata");
    }
    td.appendChild(myinput);

    row.appendChild(td);
    tbody.appendChild(row);


    row = document.createElement('tr');
    row.setAttribute('class', 'addprow');
    td = document.createElement('td');
    td.style.fontSize = '10pt';


    td.setAttribute('colspan', '3');

    td.setAttribute('class', 'subtitle ');

    mxUtils.write(td, 'Event - Data pattern');



    row.appendChild(td);
    tbody.appendChild(row);







    row = document.createElement('tr');

    row.setAttribute('class', 'addprow');



    row.appendChild(createLabel('Value:'));
    row.appendChild(createIntput(getDataValue("ser_pattern.modelDatal", 1), "ser_pattern_value", 'width:100px;'));


    row.appendChild(createLabel('Display Name:'));

    row.appendChild(createIntput(getDataValue("ser_pattern.modelDatal", 1), "ser_pattern_DisplayName", 'width:100px;'));

    tbody.appendChild(row);


    table.appendChild(tbody);
    divd2.appendChild(table);


    div.appendChild(divd2);
    /////////////////////////////////////////////////////////////////////


    var myUp = mxUtils.button("Update", function() {

        $(".modleName").remove();

        var data = "";



        var value = $(".modleNamev").val();
        data += returnInputField("modleName", value);

        $(".modelDatal").remove();

        ////////////////////////////////////////////////////////////migrate


        if ($(".migrate_event").val() != "") {



            value = "event__DisplayName;" + $(".migrate_event").val() + "__" + $(".migrate_DisplayName").val();
            data += returnInputField("migrateEvent modelDatal", value);
        }

        ////////////////////////////////////////////////////////migrate

        //////////////////////////////////////////////////////////mer

        if ($(".mer_event").val() != "") {
            value = "event__DisplayName;" + $(".mer_event").val() + "__" + $(".mer_DisplayName").val();
            data += returnInputField("mer modelDatal", value);
        }

        var merEventdata = 0;
        $(".merEventdata_event").each(function() {
            merEventdata++;
            if ($(this).val() != "") {

                value = "value__DisplayName;" + $(".merEventdata_event").eq(merEventdata - 1).val() + "__" + $(".merEventdata_DisplayName").eq(merEventdata - 1).val();
                data += returnInputField("merEventdata modelDatal  merEventdata" + merEventdata, value);


            }

        })



        if ($(".mer_pattern_value").val() != "") {

            value = "value__DisplayName;" + $(".mer_pattern_value").val() + "__" + $(".mer_pattern_DisplayName").val();
            data += returnInputField("mer_pattern modelDatal ", value);
        }



        ////////////////////////////////////////////////mer 


        ////////////////////////////////////////////////ser
        if ($(".ser_event").val() != "") {
            value = "event__DisplayName;" + $(".ser_event").val() + "__" + $(".ser_DisplayName").val();
            data += returnInputField("ser modelDatal", value);
        }

        var serEventdata = 0;
        $(".serEventdata_event").each(function() {
            serEventdata++;
            if ($(this).val() != "") {

                value = "value__DisplayName;" + $(".serEventdata_event").eq(serEventdata - 1).val() + "__" + $(".serEventdata_DisplayName").eq(serEventdata - 1).val();
                data += returnInputField("serEventdata modelDatal serEventdata" + serEventdata, value);


            }

        })
        if ($(".ser_pattern_value").val() != "") {

            value = "value__DisplayName;" + $(".ser_pattern_value").val() + "__" + $(".ser_pattern_DisplayName").val();
            data += returnInputField("ser_pattern modelDatal", value);
        }





        $(".itmedata").append(data);

        editorUi.hideDialog();


    });
    myUp.setAttribute('class', 'myupdate');


    div.appendChild(myUp);
    this.container = div;
}





